package com.example.demo.utils;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * 用户信息
 */
public class UserInfoUtil {
    /**
     * 获取Authentication
     */
    public static Authentication getAuthentication() {
        return SecurityContextHolder.getContext().getAuthentication();
    }

    /**
     * 获取用户名
     * @return
     */
    public static String gerUserName(){
        Authentication authentication = getAuthentication();
        return (String) authentication.getPrincipal();
    }
}
